a = 0
b = 0
c = 0


def start():
    print('1.求根的近似值')
    print('2.保留根号和分数')
    m = int(input('请输入模式：'))
    print()
    return m


def ask():
    global a, b, c
    a = int(input('请输入方程的二次项系数（仅支持整数）：'))
    b = int(input('请输入方程的一次项系数（仅支持整数）：'))
    c = int(input('请输入方程的常数项（仅支持整数）：'))
    print()


def one():
    global a, b, c
    ask()
    delta = b ** 2 - 4 * a * c
    if delta < 0:
        print('方程无实根')
    elif delta == 0:
        x = -b / (2 * a)
        print('方程有两个相等的实根：x1=x2=' + str(x))
    else:
        x1 = (-b + delta ** 0.5) / (2 * a)
        x2 = (-b - delta ** 0.5) / (2 * a)
        print('方程有两个不相等的实根：x1=' + str(x1) + '，x2=' + str(x2))


def two():
    global a, b, c
    ask()
    x1 = ''
    x2 = ''
    delta = b ** 2 - 4 * a * c
    p = 1
    for i in range(delta, 0, -1):
        if delta % (i ** 2) == 0:
            p = i
            delta //= (i ** 2)
            break
    for i in range(p, 0, -1):
        if p % i == 0 and b % i == 0 and (2 * a) % i == 0:
            p //= i
            b //= i
            a /= i
            break
    if delta < 0:
        print('方程无实根')
    elif delta == 0:
        if -b % (2 * a) == 0:
            x = str(-b // int(2 * a))
        else:
            for i in range(b, 0, -1):
                if b % i == 0 and (2 * a) % i == 0:
                    b //= i
                    a /= i
                    break
            x = str(-b) + '/' + str(int(2 * a))
        print('方程有两个相等的实根：x1=x2=' + x)
    else:
        if int(delta ** 0.5) == delta ** 0.5:
            if (-b + delta ** 0.5) % (2 * a) == 0:
                x1 = str(int(-b + delta ** 0.5) // int(2 * a))
            else:
                for i in range(int(2 * a), 0, -1):
                    if (-b + delta ** 0.5) % i == 0 and (2 * a) % i == 0:
                        x1 = str(int(-b + delta ** 0.5) // i) + '/' + str(int(2 * a) // i)
                        break
            if (-b - delta ** 0.5) % (2 * a) == 0:
                x2 = str(int(-b - delta ** 0.5) // int(2 * a))
            else:
                for i in range(int(2 * a), 0, -1):
                    if (-b - delta ** 0.5) % i == 0 and (2 * a) % i == 0:
                        x2 = str(int(-b - delta ** 0.5) // i) + '/' + str(int(2 * a) // i)
                        break
        else:
            if p == 1 and 2 * a == 1:
                x1 = str(-b) + '+√' + str(delta)
                x2 = str(-b) + '-√' + str(delta)
            elif p == 1:
                x1 = '(' + str(-b) + '+√' + str(delta) + ')/' + str(int(a * 2))
                x2 = '(' + str(-b) + '-√' + str(delta) + ')/' + str(int(a * 2))
            elif 2 * a == 1:
                x1 = str(-b) + '+' + str(p) + '√' + str(delta)
                x2 = str(-b) + '-' + str(p) + '√' + str(delta)
            else:
                x1 = '(' + str(-b) + '+' + str(p) + '√' + str(delta) + ')/' + str(int(a * 2))
                x2 = '(' + str(-b) + '-' + str(p) + '√' + str(delta) + ')/' + str(int(a * 2))
        print('方程有两个不相等的实根：x1=' + x1 + '，x2=' + x2)
